package com.jk.controller;

import com.alibaba.dubbo.common.json.JSON;
import com.alibaba.dubbo.common.json.JSONArray;
import com.alibaba.dubbo.common.json.JSONObject;
import com.jk.entity.Company;
import com.jk.entity.CompanyRecord;
import com.jk.entity.User;
import com.jk.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import java.io.PrintWriter;
import java.io.Writer;

import java.util.List;

/**
 * 企业管理（商铺管理）
 */
@RestController
@RequestMapping("app/pay")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    @GetMapping("selectDeptList")
    public List selectDeptList(Company company, HttpServletResponse response,HttpServletRequest request) {
//		去后台查询总条数和所有数据
        User yuebao = (User) request.getSession().getAttribute("login");
        /*String userId = yuebao.getUserId();*/
        String userId = "446c965408ed4d1cbbe32157f9bd2f32";
        List list = companyService.queryCompany(userId);
        /*response.setHeader("Access-Control-Allow-Origin", "*");
        response.setCharacterEncoding("UTF-8");
        Writer out = null;
        PrintWriter writer = null;
        try {
            writer = response.getWriter();
            String jsonStr = JSON.json(list);
            String jsonpCallback = request.getParameter("jsonpCallback");
            writer.println(jsonpCallback + "(" + jsonStr + ")");
        } catch (IOException e) {
            e.printStackTrace();
        }*/
          return list;
    }

    /**
     * 查询交易记录
     * */
    @GetMapping("selectJyjl")
    public List<CompanyRecord> selectJyjl(HttpServletRequest request){
        User yuebao = (User) request.getSession().getAttribute("login");
        String userId = "446c965408ed4d1cbbe32157f9bd2f32";
        List list = companyService.selectJyjl(userId);
        return list;
    }

    /**
     * 查询商铺余额
     * */
    @GetMapping("selectSpye")
    public Long selectSpye(Company company, HttpServletResponse response,HttpServletRequest request){
        User yuebao = (User) request.getSession().getAttribute("login");
        String userId = "446c965408ed4d1cbbe32157f9bd2f32";
        Long list = (Long) companyService.selectSpye(userId);
        return list;
    }




    @PostMapping("addCompany")
    public  void  addCompany(@RequestBody Company company){
        companyService.addCompany(company);
    }

    @PostMapping("deleteCompany")
    public boolean deleteCompany(String companyId){
       return companyService.deleteCompany(companyId);
    }




}
